#include <iostream>
#include <cstring>

//结构体
typedef struct data
{
    int n;
    struct data *next;
}DATA;

//创建链表
DATA *create()
{
    DATA* head=new DATA;
    head->next=NULL;
    return head;
}

//构建链表
void construct(DATA *head,int a[],int n)
{
    if(n==0)
    {
        return;
    }
    DATA *p;
    p=new DATA;
    p->n=a[0];
    p->next=NULL;
    head->next=p;
    for(int i=1;i<n;i++)
    {
        DATA *q=new DATA;
        q->n=a[i];
        q->next=NULL;
        p->next=q;
        p=q;
    }
}

//打印链表
void print(DATA *head)
{
    if(head->next==NULL)
    {
        return;
    }
    DATA *p=head->next;
    int pd=0;
    while(p!=NULL)
    {
        if(pd)
        {
            printf(" ");
        }
        printf("%d",p->n);
        pd=1;
        p=p->next;
    }
    printf("\n");
    return;
}

//插入
void Insert(DATA *head,int x,int y)
{
    DATA *p=head->next;
    DATA *q=head;
    for(int i=1;i<x;i++)
    {
        if (p->next == NULL)
        {
            printf("Wrong Input!\n");
            return;
        }
        q = p;
        p = p->next;
    }
    DATA *t=new DATA;
    t->n=y;
    q->next=t;
    t->next=p;
    print(head);
}

//删除
void Delete(DATA *head,int x)
{
    DATA *p=head->next;
    DATA *q=head;
    while(p!=NULL)
    {
        if(p->n==x)
        {
            q->next=p->next;
            delete p;
            print(head);
            return;
        }
        q=p;
        p=p->next;
    }
    printf("Wrong Input!\n");
    return;
}

//输出位置
void Locate(DATA *head,int x)
{
    DATA *p=head->next;
    while(p!=NULL)
    {
        static int i=1;
        if(p->n==x)
        {
            printf("%d\n",i);
            return;
        }
        i++;
        p=p->next;
    }
    printf("Wrong Input!\n");
    return;
}

void GetElem(DATA *head,int x)
{
    DATA *p=head->next;
    while(p!=NULL)
    {
        static int i=1;
        if(i==x)
        {
            printf("%d\n",p->n);
            return;
        }
        p=p->next;
        i++;
    }
    printf("Wrong Input!\n");
    return;
}

int main() {
    int n,m;
    int a[100]={0};
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    DATA *head=create();
    construct(head,a,n);
    char c[10];
    int x,y;
    for(int i=0;i<m;i++)
    {
        scanf("%s",c);
        if(0 == strcmp(c, "Insert"))
        {
            scanf("%d%d",&x,&y);
            Insert(head,x,y);
        }
        else if(0 ==strcmp(c,"Delete")) {
            scanf("%d", &x);
            Delete(head,x);
        }
        else if(0 == strcmp(c,"Locate"))
        {
            scanf("%d",&x);
            Locate(head,x);
        }
        else if(0 == strcmp(c,"GetElem"))
        {
            scanf("%d",&x);
            GetElem(head,x);
        }
    }


    return 0;
}
